package com.hitgo.soccer.config;

import java.util.HashMap;

import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class PlayerConfig
{
	public int id;		// 球员id
	public short type;		// 球员类型	前锋，后卫，守门员等等
	
	// 进攻属性
	public int speed;		 // 速度
	public int dribble; 	// 盘带
	public int shot; 		// 射门
	// end 进攻属性

	// 身体属性
	public int strength; 	// 力量
	public int energy; 	// 体能
	public int balance; 	// 平衡
	// end 身体属性

	// 防守
	public int fierce; 	// 凶猛
	public int obstruct; 	// 干扰
	public int steal; 		// 抢断
	// end 防守

	// 组织
	public int pass; 			// 传球
	public int vision;	 		// 视野
	public int conscious; 		// 意识

	public static HashMap<Integer, PlayerConfig> playerConfigs = new HashMap<Integer, PlayerConfig>();
	public static void loadConfig(String configFile)
	{
		if (configFile == null || configFile.isEmpty())
			return;
			
		// 获取文档的根元素，赋值给rootElement变量
		Element rootElement = ConfigUtil.GetRootElement(configFile);
		if(rootElement == null)
			return ;
		
		NodeList nodeList = rootElement.getElementsByTagName("RECORD");
		for(int nIndex = 0; nIndex < nodeList.getLength(); nIndex++)
		{
			Node nodeItem = nodeList.item(nIndex);
			if(nodeItem == null)
				continue ;
			PlayerConfig pConfig = new PlayerConfig();
			pConfig.id = ConfigUtil.GetAttributeIntValue(nodeItem, "id");
			pConfig.type = (short) ConfigUtil.GetAttributeIntValue(nodeItem, "type");
			
			// 速度
			pConfig.speed = ConfigUtil.GetAttributeIntValue(nodeItem, "speed");
			// 盘带
			pConfig.dribble = ConfigUtil.GetAttributeIntValue(nodeItem, "dribble");
			// 射门
			pConfig.shot = ConfigUtil.GetAttributeIntValue(nodeItem, "shot");
			

			// 力量
			pConfig.strength = ConfigUtil.GetAttributeIntValue(nodeItem, "strength");
			// 体能
			pConfig.energy = ConfigUtil.GetAttributeIntValue(nodeItem, "energy");
			// 平衡
			pConfig.balance = ConfigUtil.GetAttributeIntValue(nodeItem, "balance");
			

			// 凶猛
			pConfig.fierce = ConfigUtil.GetAttributeIntValue(nodeItem, "fierce");
			// 干扰
			pConfig.obstruct = ConfigUtil.GetAttributeIntValue(nodeItem, "obstruct");
			// 抢断
			pConfig.steal = ConfigUtil.GetAttributeIntValue(nodeItem, "steal");
			

			// 传球
			pConfig.pass = ConfigUtil.GetAttributeIntValue(nodeItem, "pass");
			// 视野
			pConfig.vision = ConfigUtil.GetAttributeIntValue(nodeItem, "vision");
			// 意识
			pConfig.conscious = ConfigUtil.GetAttributeIntValue(nodeItem, "conscious");
			
			playerConfigs.put(pConfig.id, pConfig);
		}
	}

	public static PlayerConfig getPlayerConfig(int playerID)
	{
		return playerConfigs.get(playerID);
	}
}
